<template>
  <div class="">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <span class="el-dropdown-link">
        订单状态
      </span>
      <el-select v-model="state" clearable placeholder="请选择">
        <el-option
          v-for="item in stateList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <span class="label">订单号</span>
      <el-form-item>
        <el-input v-model="orderNo" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <br>
      <span class="label">发布时间</span>
      <el-date-picker
        v-model="time"
        type="daterange"
        style="width: 380px;"
        range-separator="至"
        value-format="yyyy-MM-dd"
        start-placeholder="开始日期"
        end-placeholder="结束日期">
      </el-date-picker>
      <el-form-item >
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
        >
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="center"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="customerNickname"
        header-align="center"
        align="center"
        label="客人昵称">
      </el-table-column>
      <el-table-column
        prop="customerPhone"
        header-align="center"
        align="center"
        label="客人电话">
      </el-table-column>
      <el-table-column
        prop="goodsTotalEur"
        header-align="center"
        align="center"
        width="150"
        label="商品总价">
        <template slot-scope="scope">
          €{{scope.row.goodsTotalEur}} | ￥{{scope.row.goodsTotalCny}}
        </template>
      </el-table-column>
      <el-table-column
        prop="eurRate"
        header-align="center"
        align="center"
        label="汇率">
        <template slot-scope="scope">
          1 : {{scope.row.eurRate}}
        </template>
      </el-table-column>
      <el-table-column
        prop="discountTotalPrice"
        header-align="center"
        align="center"
        label="优惠金额">
        <template slot-scope="scope">
          <template v-if="scope.row.discountTotalPrice == 0" >
            - ￥{{ scope.row.discountTotalPrice }}
          </template>
          <template v-else >
            <el-popover trigger="hover" placement="top">
              <template v-if="scope.row.goodsDiscountPrice != 0">
                <p>商品优惠: - ￥{{ scope.row.goodsDiscountPrice }}</p>
              </template>
              <template v-if="scope.row.couponDiscountPrice != 0">
                <p>优惠券优惠: - ￥{{ scope.row.couponDiscountPrice }}</p>
              </template>
              <template v-if="scope.row.birthdayMonthDiscountPrice != 0">
                <p>生日月优惠: - ￥{{ scope.row.birthdayMonthDiscountPrice }}</p>
              </template>
              <div slot="reference" class="name-wrapper">
                - ￥{{ scope.row.discountTotalPrice }}
              </div>
            </el-popover>
          </template>
        </template>
      </el-table-column>
       <el-table-column
        prop="freight"
        header-align="center"
        align="center"
        label="运费">
        <template slot-scope="scope">
          ￥{{ scope.row.freight }}
        </template>
      </el-table-column>
      <el-table-column
        prop="amountPaid"
        header-align="center"
        align="center"
        label="实付金额">
        <template slot-scope="scope">
          ￥{{ scope.row.amountPaid }}
        </template>
      </el-table-column>
       <el-table-column
        prop="totalNumber"
        header-align="center"
        align="center"
        label="数量">
      </el-table-column>
      <el-table-column
        prop="reciveName"
        header-align="center"
        align="center"
        label="收货人">
      </el-table-column>
           <el-table-column
        prop="recivePhone"
        header-align="center"
        align="center"
        label="收货人电话">
      </el-table-column>
      <el-table-column
        prop="reciveAddress"
        header-align="center"
        align="center"
        label="收货地址">
      </el-table-column>
      <el-table-column
        prop="miyu"
        header-align="center"
        align="center"
        label="密语">
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          {{returnStateNumToZH(scope.row.state)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        prop="detail"
        header-align="center"
        align="center"
        label="Action">
        <template slot-scope="scope">
          <a :href="'#/biz-orderdetail?orderNo='+scope.row.orderNo+'&state='+scope.row.state">详情</a>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>

  </div>
</template>

<script>
import AddOrUpdate from "./orders-add-or-update";
export default {
  data() {
    return {
      dataForm: {
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      orderNo: "",
      state: "",
      stateList: [
        {
          value: 0,
          label: "已下单"
        },
        {
          value: 1,
          label: "待付款"
        },
        {
          value: 2,
          label: "已付款"
        },
        {
          value: 3,
          label: "待完善信息"
        },
        {
          value: 9,
          label: "已上传购买凭证"
        },
        {
          value: 10,
          label: "已上传打包信息"
        },
        {
          value: 4,
          label: "已发货"
        },
        {
          value: 5,
          label: "已确认收货"
        },
        {
          value: 6,
          label: "买手已评价"
        },
        {
          value: 7,
          label: "客人已评价"
        },
        {
          value: 8,
          label: "订单完成"
        },
        {
          value: 11,
          label: "交易关闭"
        },
        {
          value: -1,
          label: "订单取消"
        },
        {
          value: -2,
          label: "订单超时"
        }
      ],
      time: ""
    };
  },
  computed: {},
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    returnStateNumToZH(stateNum) {
      if (stateNum == 0) {
        return "已下单";
      }
      if (stateNum == 1) {
        return "待付款";
      }
      if (stateNum == 2) {
        return "已付款";
      }
      if (stateNum == 3) {
        return "待完善信息";
      }
      if (stateNum == 9) {
        return "已上传购买凭证";
      }
      if (stateNum == 10) {
        return "已上传打包信息";
      }
      if (stateNum == 4) {
        return "已发货";
      }
      if (stateNum == 5) {
        return "已确认收货";
      }
      if (stateNum == 6) {
        return "买手已评价";
      }
      if (stateNum == 7) {
        return "客人已评价";
      }
      if (stateNum == 8) {
        return "订单完成";
      }
      if (stateNum == 11) {
        return "交易关闭";
      }
      if (stateNum == -1) {
        return "订单取消";
      }
      if (stateNum == -2) {
        return "订单超时";
      }
    },
    // 获取数据列表
    getDataList() {
      console.log(this.time);
      this.dataListLoading = true;
      var startTime
      var endTime
      if (this.time) {
        startTime=this.time[0];
        endTime=this.time[1];
      }
      this.$http({
        url: this.$http.adornUrl("/biz/orders/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          startTime: startTime,
          endTime: endTime,
          orderNo: this.orderNo,
          status: this.state
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map(item => {
            return item.id;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/biz/orders/delete"),
          method: "post",
          data: this.$http.adornData(ids, false)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>
<style>
</style>
